package com.spring.wx.oauth.dao;

import com.spring.wx.oauth.entity.UserEntity;
import com.spring.wx.oauth.entity.WxLoginUser;
import org.apache.ibatis.annotations.*;

/**
 * Copyright: yueyong (c) 2022
 *
 * @author he.shaorong
 * @version 1.0
 * @date 2022/7/1
 */
@Mapper
public interface WxLoginMapper {
    @Select("select * from wx_user_login where openid = #{openid}")
    WxLoginUser getOpenid(@Param(value = "openid") String openid);

    @Insert("insert into wx_user_login(id, sex, openid, state, nickname, phone, city, image) values(#{id}, #{sex}, #{openid}, #{state}, #{nickname}, #{phone}, #{city}, #{image})")
    @SelectKey(statement = "select concat('ac-', date_format(now(), '%Y%m%d'), '-', lower(uuid())) as id", keyProperty = "id", resultType = String.class, before = true)
    int insert(WxLoginUser wxLoginUser);

    @Update("update wx_user_login set nickname = #{nickname}, image = #{image}, phone = #{phone} , city = #{city}, sex = #{sex} ,state = #{state} where openid = #{openid}")
    int update(WxLoginUser wxLoginUser);
}
